/*
 * Created on Dec 5, 2003
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.vectrics.company.web.struts;

import java.util.Collection;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.vectrics.common.db.DisplayUtils;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.struts.Request;
import org.vectrics.struts.VectricsActionForm;

public class CompanyForm extends VectricsActionForm {

	private static final long serialVersionUID = -1395905885238365626L;
	
	private transient static Logger log = Logger.getLogger(CompanyForm.class);
	private String companyId = null;
	private String referenceId = null;
	private String parentId = null;
	private String name = null;
	private String description = null;
	private String address1 = null;
	private String address2 = null;
	private String postalCode = null;
	private String phone = null;
	private String phone2 = null;
	private String background = null;
	private String createDomain = "false";
	private String sectorCode = null;
	private Collection sectors = null;
	private String locationId = null;
	
	/**
	 * 
	 */
	public CompanyForm() {
		super();
	}

	public ActionErrors doValidate(ActionMapping mapping, Request request) {
		ActionErrors errors = new ActionErrors();
		if (this.wasButtonPressed(request, "cancel") == false) {
			if ((this.getName() == null) || (this.getName().trim().length() <= 0)) {
				log.debug("validate encountered error - name missing");
				errors.add("name", new ActionMessage("error.company.name.missing"));
			}
			if ((locationId==null) || (locationId.trim().equals(""))) {
				errors.add("location" , new ActionMessage("error.company.location"));
			}
		}
		Collection allSectors = RecruitServiceLocator.getCompanyService().findAllSectors();
		request.setAttribute("sectors", DisplayUtils.sectorTypesToCoded(allSectors, request.getLocale()));
		request.setSessionAttribute("sectors", DisplayUtils.sectorTypesToCoded(allSectors, request.getLocale()));
		CompanyForm.prepareAttributes(request);
		return(errors);
	}
	
	public static void prepareAttributes(Request request) {
		Collection allSectors = RecruitServiceLocator.getCompanyService().findAllSectors();
		request.setAttribute("sectors", DisplayUtils.sectorTypesToCoded(allSectors, request.getLocale()));
		request.setSessionAttribute("sectors", DisplayUtils.sectorTypesToCoded(allSectors, request.getLocale()));
	}
	
	/**
	 * @return
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 */
	public void setName(String name) {
		this.name = name;
	}

    /**
     * @return Returns the companyId.
     */
    public String getCompanyId() {
        return companyId;
    }
    /**
     * @param companyId The companyId to set.
     */
    public void setCompanyId(String companyId) {
        this.companyId = companyId;
    }
	/**
	 * @return
	 */
	public String getParentId() {
		return parentId;
	}

	/**
	 * @param parentId
	 */
	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	/**
	 * @return
	 */
	public String getAddress1() {
		return address1;
	}

	/**
	 * @param address1
	 */
	public void setAddress1(String address1) {
		this.address1 = address1;
	}

	/**
	 * @return
	 */
	public String getAddress2() {
		return address2;
	}

	/**
	 * @param address2
	 */
	public void setAddress2(String address2) {
		this.address2 = address2;
	}

	/**
	 * @return
	 */
	public String getPostalCode() {
		return postalCode;
	}

	/**
	 * @param postalCode
	 */
	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}

	/**
	 * @return
	 */
	public String getPhone() {
		return phone;
	}

	/**
	 * @param phone
	 */
	public void setPhone(String phone) {
		this.phone = phone;
	}

	/**
	 * @return Returns the referenceId.
	 */
	public String getReferenceId() {
		return referenceId;
	}
	
	/**
	 * @param referenceId The referenceId to set.
	 */
	public void setReferenceId(String referenceId) {
		this.referenceId = referenceId;
	}
    /**
     * @return Returns the background.
     */
    public String getBackground() {
        return background;
    }
    
    /**
     * @param background The background to set.
     */
    public void setBackground(String background) {
        this.background = background;
    }

	/**
	 * @return Returns the createDomain.
	 */
	public String getCreateDomain() {
		return createDomain;
	}

	/**
	 * @param createDomain The createDomain to set.
	 */
	public void setCreateDomain(String createDomain) {
		this.createDomain = createDomain;
	}

	/**
	 * @return Returns the phone2.
	 */
	public String getPhone2() {
		return phone2;
	}

	/**
	 * @param phone2 The phone2 to set.
	 */
	public void setPhone2(String phone2) {
		this.phone2 = phone2;
	}

	public String getSectorCode() {
		return sectorCode;
	}

	public void setSectorCode(String sectorCode) {
		this.sectorCode = sectorCode;
	}

	public Collection getSectors() {
		return sectors;
	}

	public void setSectors(Collection sectors) {
		this.sectors = sectors;
	}

	/**
	 * @return the locationId
	 */
	public String getLocationId() {
		return locationId;
	}

	/**
	 * @param locationId the locationId to set
	 */
	public void setLocationId(String locationId) {
		this.locationId = locationId;
	}
        
}
